#include "bsp_light_sw.h"

#include "Mini58Series.h"

void bsp_light_sw_init(void) {
  GPIO_SetMode(LIGHT_SW_1_A_GPIO, LIGHT_SW_1_A_IO, GPIO_MODE_INPUT);
  GPIO_SetMode(LIGHT_SW_1_B_GPIO, LIGHT_SW_1_B_IO, GPIO_MODE_INPUT);
  GPIO_SetMode(LIGHT_SW_2_A_GPIO, LIGHT_SW_2_A_IO, GPIO_MODE_INPUT);
  GPIO_SetMode(LIGHT_SW_2_B_GPIO, LIGHT_SW_2_B_IO, GPIO_MODE_INPUT);
}

uint8_t bsp_light_sw_get(uint8_t gn) {
  uint8_t sta = 0;
  if (gn == 0) {
    (LIGHT_SW_1_B_PIN) ? (sta &= (~0x01)) : (sta |= 0x01);
    sta <<= 1;
    (LIGHT_SW_1_A_PIN) ? (sta &= (~0x01)) : (sta |= 0x01);
  }
  if (gn == 1) {
    (LIGHT_SW_2_A_PIN) ? (sta &= (~0x01)) : (sta |= 0x01);
    sta <<= 1;
    (LIGHT_SW_2_B_PIN) ? (sta &= (~0x01)) : (sta |= 0x01);
  }
  return sta;
}
